﻿using System;
using System.Linq.Expressions;
using System.Web.Mvc;
using System.Web.Routing;

namespace TypedMvcActionHelper
{
    public class MvcInvocationDefinition
    {
        public string ControllerName { get; set; }
        public string ActionName { get; set; }
        public RouteValueDictionary RouteValues { get; set; }

        private MvcInvocationDefinition(string controllerName,string actionName,RouteValueDictionary routeValues)
        {
            ControllerName = controllerName;
            ActionName = actionName;
            RouteValues = routeValues;
        }

        public static MvcInvocationDefinition Create<TController>(Expression<Func<TController, ActionResult>> expression)
             where TController : ControllerBase
        {
            var expressionExtractor = MvcActionExpressionExtractor.For<TController>();

            var controllerName = expressionExtractor.GetControllerName();
            var actionName = expressionExtractor.GetActionName(expression);
            var routeValueDictionary = expressionExtractor.GetRouteValueDictionary(expression);

            return new MvcInvocationDefinition(controllerName, actionName, routeValueDictionary);
        }
    }
   
}